package com.epfresh.supplier.adapter;

import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.epfresh.supplier.R;
import com.epfresh.supplier.entity.MerChantInfo;
import com.epfresh.supplier.entity.ProductReturnInfoReasonList;

import multitype.ItemViewBinder;
import multitype.OnRecyclerViewItemClickListener;


public class ReturnReasonItemAdapter extends ItemViewBinder<ProductReturnInfoReasonList,ReturnReasonItemAdapter.ViewHolder> implements View.OnClickListener {


    OnRecyclerViewItemClickListener onRecyclerViewItemClickListener;

    public OnRecyclerViewItemClickListener getOnRecyclerViewItemClickListener() {
        return onRecyclerViewItemClickListener;
    }

    public void setOnRecyclerViewItemClickListener(OnRecyclerViewItemClickListener onRecyclerViewItemClickListener) {
        this.onRecyclerViewItemClickListener = onRecyclerViewItemClickListener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater layoutInflater, @NonNull ViewGroup viewGroup) {
        View view = layoutInflater.inflate(R.layout.item_return_reason, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder viewHolder, @NonNull ProductReturnInfoReasonList post) {
        int position = getPosition(viewHolder);
        viewHolder.itemView.setTag(R.id.item_key_position,position);
        viewHolder.itemView.setTag(R.id.item_key_status,post);
        viewHolder.itemView.setOnClickListener(this);

        if (post.isSelect()){
           /* Drawable drawable= viewHolder.tvName.getContext().getResources().getDrawable(R.mipmap.icon_current_store);
            // 这一步必须要做,否则不会显示.
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            viewHolder.tvName.setCompoundDrawables(drawable,null,null,null);*/
            viewHolder.tvName.setTextColor(0xffff0000);

            viewHolder.iv.setImageResource(R.mipmap.register_read);
        }else {
            viewHolder.tvName.setTextColor(0xff626262);
//            viewHolder.tvName.setCompoundDrawables(null,null,null,null);
            viewHolder.iv.setImageResource(R.mipmap.register_unread);
        }
        viewHolder.tvName.setText(post.getTitle());
    }

    @Override
    public void onClick(View v) {
        Object p = v.getTag(R.id.item_key_position);
        Object o = v.getTag(R.id.item_key_status);
        if (p!= null && p instanceof Integer && o != null && onRecyclerViewItemClickListener != null){
            onRecyclerViewItemClickListener.onItemClick(v, (Integer) p,o);
        }
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {


        TextView tvName;
        ImageView iv;


        ViewHolder(View itemView) {
            super(itemView);

            tvName = itemView.findViewById(R.id.tv_name);
            iv = itemView.findViewById(R.id.iv_select);
        }
    }


}
